<HTML>
<HEAD>
<TITLE>
RegistroMemoria.cpp
</TITLE>
</HEAD>
<BODY>
<PRE>
<font color="blue">#include</font> <font color="maroon">"RegistroMemoria.h"</font>

RegistroMemoria<font color="black">:</font><font color="black">:</font>RegistroMemoria<font color="black">(</font>TipoMemoria tipo, <font color="blue">int</font> tamanio, <font color="blue">void</font><font color="black">*</font> accesoMemoria<font color="black">)</font><font color="black">{</font>
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tipoMemoria <font color="black">=</font> tipo;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tamanio <font color="black">=</font> tamanio;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p <font color="black">=</font> accesoMemoria;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>dato <font color="black">=</font> NULL;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>id <font color="black">=</font> ComponenteAlmacenamiento<font color="black">:</font><font color="black">:</font>idSinAsignar;
<font color="black">}</font>

RegistroMemoria<font color="black">:</font><font color="black">:</font>RegistroMemoria<font color="black">(</font>TipoMemoria tipo, <font color="blue">int</font> tamanio, <font color="blue">void</font><font color="black">*</font> accesoMemoria, Dato <font color="black">*</font>dato<font color="black">)</font><font color="black">{</font>
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tipoMemoria <font color="black">=</font> tipo;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tamanio <font color="black">=</font> tamanio;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p <font color="black">=</font> accesoMemoria;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>dato <font color="black">=</font> dato;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>id <font color="black">=</font> ComponenteAlmacenamiento<font color="black">:</font><font color="black">:</font>idSinAsignar;
<font color="black">}</font>

<font color="blue">void</font> RegistroMemoria<font color="black">:</font><font color="black">:</font>getAccesoDato<font color="black">(</font><font color="blue">void</font> <font color="black">*</font><font color="black">*</font>accesoDato<font color="black">)</font><font color="black">{</font>
    <font color="black">*</font>accesoDato <font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p;
<font color="black">}</font>

<font color="blue">void</font> RegistroMemoria<font color="black">:</font><font color="black">:</font>leer<font color="black">(</font>Dato <font color="black">*</font>datoLeido, TipoSerializacion modo<font color="black">)</font><font color="black">{</font>
    <font color="blue">if</font><font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p<font color="black">=</font><font color="black">=</font>NULL<font color="black">)</font>
        <font color="blue">throw</font> <font color="blue">new</font> NullPointerException<font color="black">(</font><font color="black">)</font>;
    <font color="blue">int</font> bytesDato <font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tamanio;
    <font color="blue">void</font> <font color="black">*</font>pos;
    pos <font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p;
    <font color="blue">void</font> <font color="black">*</font>verificacion;
    <font color="blue">if</font><font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tipoMemoria<font color="black">!</font><font color="black">=</font>FIJA<font color="black">)</font><font color="black">{</font>
        verificacion <font color="black">=</font> memmove<font color="black">(</font><font color="black">&</font>bytesDato, <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p, Registro<font color="black">:</font><font color="black">:</font>bytesControlTamanio<font color="black">)</font>;
        <font color="blue">if</font><font color="black">(</font>verificacion<font color="black">!</font><font color="black">=</font><font color="black">(</font><font color="blue">void</font><font color="black">*</font><font color="black">)</font><font color="black">&</font>bytesDato<font color="black">)</font>
            <font color="blue">throw</font> <font color="blue">new</font> MemoryStorageException<font color="black">(</font>StorageException<font color="black">:</font><font color="black">:</font>lectura<font color="black">)</font>;
        pos <font color="black">=</font> <font color="black">(</font><font color="blue">char</font><font color="black">*</font><font color="black">)</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p <font color="black">+</font> Registro<font color="black">:</font><font color="black">:</font>bytesControlTamanio;
    <font color="black">}</font>
    <font color="blue">void</font><font color="black">*</font> miDato;
    miDato <font color="black">=</font> malloc<font color="black">(</font>bytesDato<font color="black">)</font>;
    verificacion <font color="black">=</font> memmove<font color="black">(</font>miDato,pos,bytesDato<font color="black">)</font>;   
    <font color="blue">if</font><font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tipoMemoria<font color="black">!</font><font color="black">=</font>FIJA<font color="black">)</font>
        <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tamanio <font color="black">+</font><font color="black">=</font> Registro<font color="black">:</font><font color="black">:</font>bytesControlTamanio;
    datoLeido<font color="black">-</font><font color="black">&#62;</font>unserialize<font color="black">(</font>miDato, modo<font color="black">)</font>;
    free<font color="black">(</font>miDato<font color="black">)</font>;   
<font color="black">}</font>

<font color="blue">void</font> RegistroMemoria<font color="black">:</font><font color="black">:</font>escribir<font color="black">(</font><font color="blue">void</font> <font color="black">*</font>accesoMemoria, TipoSerializacion modo<font color="black">)</font><font color="black">{</font>
    <font color="blue">if</font><font color="black">(</font>accesoMemoria<font color="black">=</font><font color="black">=</font>NULL<font color="black">)</font>
        <font color="blue">throw</font> <font color="blue">new</font> NullPointerException<font color="black">(</font><font color="black">)</font>;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p <font color="black">=</font> accesoMemoria;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>escribirEnMemoria<font color="black">(</font>modo<font color="black">)</font>;
<font color="black">}</font>

<font color="blue">void</font> RegistroMemoria<font color="black">:</font><font color="black">:</font>escribir<font color="black">(</font>TipoSerializacion modo<font color="black">)</font><font color="black">{</font>
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>escribirEnMemoria<font color="black">(</font>modo<font color="black">)</font>;
<font color="black">}</font>

<font color="blue">void</font> RegistroMemoria<font color="black">:</font><font color="black">:</font>escribir<font color="black">(</font><font color="blue">void</font> <font color="black">*</font>accesoMemoria, Dato <font color="black">*</font>dato, TipoSerializacion modo<font color="black">)</font><font color="black">{</font>
    <font color="blue">if</font><font color="black">(</font>accesoMemoria<font color="black">=</font><font color="black">=</font>NULL<font color="black">)</font>
        <font color="blue">throw</font> <font color="blue">new</font> NullPointerException<font color="black">(</font><font color="black">)</font>;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>dato <font color="black">=</font> dato;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tamanio <font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>dato<font color="black">-</font><font color="black">&#62;</font>getTamanio<font color="black">(</font>modo<font color="black">)</font> <font color="black">+</font> Registro<font color="black">:</font><font color="black">:</font>bytesControlTamanio;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>escribirEnMemoria<font color="black">(</font>modo<font color="black">)</font>;
<font color="black">}</font>

<font color="blue">void</font> RegistroMemoria<font color="black">:</font><font color="black">:</font>borrar<font color="black">(</font><font color="black">)</font><font color="black">{</font> 
    <font color="blue">if</font><font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p<font color="black">=</font><font color="black">=</font>NULL<font color="black">)</font>
        <font color="blue">throw</font> <font color="blue">new</font> NullPointerException<font color="black">(</font><font color="black">)</font>;
    free<font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>dato<font color="black">)</font>;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>dato <font color="black">=</font> NULL;
<font color="black">}</font>

<font color="blue">void</font> RegistroMemoria<font color="black">:</font><font color="black">:</font>escribirEnMemoria<font color="black">(</font>TipoSerializacion modo<font color="black">)</font><font color="black">{</font>
    <font color="blue">void</font> <font color="black">*</font>verificacion;
    <font color="blue">void</font> <font color="black">*</font>pos;
    pos <font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p;
    <font color="blue">if</font><font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tipoMemoria<font color="black">!</font><font color="black">=</font>FIJA<font color="black">)</font><font color="black">{</font>
        <font color="blue">int</font> datosAEscribir <font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>dato<font color="black">-</font><font color="black">&#62;</font>getTamanio<font color="black">(</font>modo<font color="black">)</font>;
        verificacion <font color="black">=</font> memmove<font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p, <font color="black">&</font>datosAEscribir, Registro<font color="black">:</font><font color="black">:</font>bytesControlTamanio<font color="black">)</font>;
        <font color="blue">if</font><font color="black">(</font>verificacion<font color="black">!</font><font color="black">=</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p<font color="black">)</font>;
            <font color="blue">throw</font> <font color="blue">new</font> MemoryStorageException<font color="black">(</font>StorageException<font color="black">:</font><font color="black">:</font>escritura<font color="black">)</font>;
        pos <font color="black">=</font> <font color="black">(</font><font color="blue">char</font><font color="black">*</font><font color="black">)</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p <font color="black">+</font> Registro<font color="black">:</font><font color="black">:</font>bytesControlTamanio;
    <font color="black">}</font>
    <font color="blue">void</font> <font color="black">*</font>datoAEscribir<font color="black">=</font>NULL;
    datoAEscribir <font color="black">=</font> malloc<font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>dato<font color="black">-</font><font color="black">&#62;</font>getTamanio<font color="black">(</font>modo<font color="black">)</font><font color="black">)</font>;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>dato<font color="black">-</font><font color="black">&#62;</font>serialize<font color="black">(</font><font color="black">&</font>datoAEscribir, modo<font color="black">)</font>;
    verificacion <font color="black">=</font> memmove<font color="black">(</font>pos,datoAEscribir,<font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>dato<font color="black">-</font><font color="black">&#62;</font>getTamanio<font color="black">(</font>modo<font color="black">)</font><font color="black">)</font>;
    <font color="blue">if</font><font color="black">(</font>verificacion<font color="black">!</font><font color="black">=</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>p<font color="black">)</font>
        <font color="blue">throw</font> <font color="blue">new</font> MemoryStorageException<font color="black">(</font>StorageException<font color="black">:</font><font color="black">:</font>escritura<font color="black">)</font>;
    free<font color="black">(</font>datoAEscribir<font color="black">)</font>;
<font color="black">}</font>

</PRE>
</BODY>
</HTML>
